package com.wangyan.javabean2doc;

import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;

/**
 * @author wangyan
 * @date 2024/02/18/17:42
 * @description
 */
public class HtmlTransferable implements Transferable {
    private final String htmlData;

    public HtmlTransferable(String html) {
        this.htmlData = html;
    }

    @Override
    public DataFlavor[] getTransferDataFlavors() {
        return new DataFlavor[]{DataFlavor.stringFlavor, createHtmlDataFlavor()};
    }

    @Override
    public boolean isDataFlavorSupported(DataFlavor flavor) {
        return flavor.equals(DataFlavor.stringFlavor) || flavor.equals(createHtmlDataFlavor());
    }

    @Override
    public Object getTransferData(DataFlavor flavor) {
        return htmlData;
    }

    // 创建一个表示HTML的DataFlavor
    private static DataFlavor createHtmlDataFlavor() {
        return DataFlavor.selectionHtmlFlavor;
    }



}
